const Router = require("koa-router");
const router =  new Router();
const db = require("../db");

router.get("/api/store/:id",async (ctx,next)=>{
    let {id} = ctx.params;
    let goodsData = (await db.select(`select * from goods where id=${id}`))[0];
    let list = await db.select(`select * from productlist where type=${id}`);
    ctx.body = {
       code:0,
       goodsData,
       list
    }
})


router.get("/api/productlist",async (ctx,next)=>{
    let {page,size} = ctx.query;
    let now = (page-1)*size;

    let data = await db.select(`select * from productlist limit ${now},${size}`);
    if(data.length!==0){
        ctx.body = {
            code:0,
            data:data
        }
    }else{
        ctx.body = {
            code:1,
            msg:"加载完毕"
        }
    }
    
})





module.exports = router;